/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import controller.ControllerPaciente;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.Paciente;

/**
 *
 * @author Logatti
 */
public class TablePaciente extends AbstractTableModel {

    private static List<Paciente> linhas;
    private final List<String> colunas = Arrays.asList("id", "Nome", "Sexo", "Idade","Estado Civil", "Endereco");

    @Override
    public int getRowCount() {
        return linhas.size();
    }

    @Override
    public int getColumnCount() {
        return colunas.size();
    }

    @Override
    public String getColumnName(int column) {
        return colunas.get(column);
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Paciente p = linhas.get(rowIndex);
        switch (columnIndex) {

            case 0:
                return p.getId();
            case 1:
                return p.getNome();
            case 2:
                return p.getSexo();
            case 3:
                return p.getIdade();
            case 4:
                return p.getEstadoCivil();
            case 5:
                return p.getEndereco();
           
            default:
                throw new IndexOutOfBoundsException("ERRO: columnIndex out of  bounds");
        }
    }

    public List<Paciente> fillingRows() {

        ControllerPaciente ce = new ControllerPaciente();
        linhas = new ArrayList();
        linhas = ce.listarTodos();
        return linhas;

    }
}
